package edu.mcw.rgd.clinminer.domain;

import javax.persistence.Column;
import javax.persistence.EntityManager;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PersistenceContext;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.tostring.RooToString;

import edu.mcw.rgd.clinminer.domain.common.Persistable;
import edu.mcw.rgd.clinminer.domain.enums.RelationshipType;

@RooJavaBean
@RooToString
@RooJpaActiveRecord
@Table(name = "RELATIONSHIP")
public class Relationship implements Persistable {
	@Id
	@GeneratedValue(generator = "Relationship_IDs_Seq")
	@SequenceGenerator(name = "Relationship_IDs_Seq", sequenceName = "Relationship_IDs_Seq", allocationSize = 1)
	@Column(name = "relationship_id")
	private Long id;

	@ManyToOne
	@JoinColumn(name = "source")
	@NotNull(message = "Source participant in this relationship cannot be empty")
	private Participant source;

	@NotNull(message = "Relationship type cannot be empty")
	@Enumerated(EnumType.STRING)
	@Column(name = "relationship_type")
	private RelationshipType relationshipType;

	@ManyToOne
	@JoinColumn(name = "target")
	@NotNull(message = "Target participant in this relationship cannot be empty")
	private Participant target;

	@PersistenceContext(unitName = "persistenceUnit")
	transient EntityManager entityManager;
}
